/*
 * Created on Feb 20, 2005
 * Created by dfhuynh
 */
package edu.mit.simile.longwell.query.bucket;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;

import edu.mit.simile.longwell.Profile;
import edu.mit.simile.longwell.query.project.IProjection;
import edu.mit.simile.longwell.query.project.ITextIndexProjection;

/**
 * @author dfhuynh
 */
public class TextIndexBucketer extends BucketerBase {

	/**
	 * @param profile
	 */
	public TextIndexBucketer(Profile profile) {
		super(profile);
	}

	/* (non-Javadoc)
	 * @see edu.mit.simile.longwell.query.bucket.BucketerBase#internalGetBucket(edu.mit.simile.longwell.query.project.IProjection, java.lang.String)
	 */
	protected Set internalGetBucket(IProjection projection, String parameter) {
		ITextIndexProjection tiProjection = (ITextIndexProjection) projection;
		
		return tiProjection.search(parameter);
	}

	/* (non-Javadoc)
	 * @see edu.mit.simile.longwell.query.bucket.BucketerBase#internalSuggestNarrowingBuckets(edu.mit.simile.longwell.query.project.IProjection, float)
	 */
	protected List internalSuggestNarrowingBuckets(IProjection projection,
			float desirable) {
		return new ArrayList();
	}

	/* (non-Javadoc)
	 * @see edu.mit.simile.longwell.query.bucket.BucketerBase#internalSuggestBroadeningBuckets(edu.mit.simile.longwell.query.project.IProjection, java.lang.String)
	 */
	protected BroadeningResult internalSuggestBroadeningBuckets(
			IProjection projection, String parameter) {

		List existingBuckets = new ArrayList();
		
		existingBuckets.add(new Bucket(
			this.getClass().getName(), 
			parameter,
			parameterToLabel(parameter, projection.getLocale()),
			0));

		return new BroadeningResult(existingBuckets, new ArrayList());
	}

	/* (non-Javadoc)
	 * @see edu.mit.simile.longwell.query.bucket.BucketerBase#individualParameterToDescription(java.lang.String, java.lang.String)
	 */
	protected String individualParameterToDescription(
			String parameter, String locale) {

		return parameterToLabel(parameter, locale);
	}
	
	protected String parameterToLabel(String parameter, String locale) {
		ResourceBundle resources = ResourceBundle.getBundle(
				TextIndexBucketer.class.getName());
		
		return MessageFormat.format(
			resources.getString("ParameterLabelFormat"), 
			new Object[] {parameter});
	}
}
